package com.seres.util;


import cn.hutool.core.date.DateTime;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.util.unit.DataUnit;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description : 日期处理类
 * @ClassName : DateUtil
 * @Author : 程磊
 * @Date: 2020-06-24 16:04
 */
public class DateUtil extends cn.hutool.core.date.DateUtil {

    /**
     * @description 获取一个整型年月日
     * @author 程磊
     * @Date 2020/6/24 16:08
     * @return: int
     */
    public static int getIntDay(){
        return getIntDay(new Date());
    }

    /**
     * @description 获取一个整型年月日
     * @param date 日期
     * @author 程磊
     * @Date 2020/6/24 16:08
     * @return: int
     */
    public static int getIntDay(Date date){
        return NumberUtils.toInt(format(date,"yyyyMMdd"));
    }
    /**
     * @description  获取一个整型年月
     * @param date: 日期
     * @author 赖星
     * @Date 2020/8/10 0010 下午 16:18
     * @return: int
     */
    public static int getIntMonth(Date date){
        return NumberUtils.toInt(format(date,"yyyyMM"));
    }
    public static int getIntMonth(){
        return getIntMonth(new Date());
    }
    /**
     * @description 毫秒转化天时分秒
     * @param ms: 
     * @author 扶滨
     * @Date 2020/7/27 2:07 下午 
     * @return: java.lang.String
     */
    public static String formatTime(long ms) {
        int ss = 1000;
        int mi = ss * 60;
        int hh = mi * 60;
        int dd = hh * 24;

        long day = ms / dd;
        long hour = (ms - day * dd) / hh;
        long minute = (ms - day * dd - hour * hh) / mi;
        long second = (ms - day * dd - hour * hh - minute * mi) / ss;
        long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

        String strDay = day < 10 ? "0" + day : "" + day; //天
        String strHour = hour < 10 ? "0" + hour : "" + hour;//小时
        String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟
        String strSecond = second < 10 ? "0" + second : "" + second;//秒
        String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;//毫秒
        strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;
        if (day>0){
            return strDay +"天"+strHour+"时"+strMinute + "分" ;
        }
        if (day<1 && hour>0){
            return strHour+"时"+strMinute + "分";
        }
        return strMinute + "分" ;
    }
    /**
     * @description 搜索时间
     * @param startTime:
     * @param endTime:
     * @author 扶滨
     * @Date 2020/7/28 5:58 下午
     * @return: java.util.Map<java.lang.String,java.lang.String>
     */
    public static Map<String,String> time(String startTime, String endTime){
        if (StringUtils.isBlank(startTime) || StringUtils.isBlank(endTime)){
            return null;
        }else {
            Map<String,String> map = new HashMap<>();
            Date parse = DateUtil.parseDate(startTime);
            Date parse1 = DateUtil.parseDate(endTime);
            String format = DateUtil.formatDate(parse);
            String format1 = DateUtil.formatDate(parse1);
            startTime = format+" 00:00:00";
            endTime = format1+" 23:59:59";
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            return map;
        }
    }

    /**
     * @description 搜索时间
     * @param startLongTime: 完成时间
     * @param endLongTime:完成时间
     * @author 扶滨
     * @Date 2020/7/28 5:58 下午
     * @return: java.util.Map<java.lang.String,java.lang.String>
     */
    public static Map<String,Long> longTime(String startLongTime, String endLongTime){
        if (StringUtils.isBlank(startLongTime) || StringUtils.isBlank(endLongTime)){
            return null;
        }else {
            Map<String,Long> map = new HashMap<>();
            Date parse = DateUtil.parseDate(startLongTime);
            Date parse1 = DateUtil.parseDate(endLongTime);
            String format = DateUtil.formatDate(parse);
            String format1 = DateUtil.formatDate(parse1);
            startLongTime = format+" 00:00:00";
            endLongTime = format1+" 23:59:59";
            Long startTime = DateUtil.parseDateTime(startLongTime).getTime();
            Long endTime = DateUtil.parseDateTime(endLongTime).getTime();
            map.put("startLongTime",startTime);
            map.put("endLongTime",endTime);
            return map;
        }
    }
}
